{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "678ce984-841d-49bd-b2c5-8586aaed05b2",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c8866271-04d5-4bd6-9916-f55bc5889968",
   "metadata": {},
   "source": [
    "### Eigenvalues and Eigenvectors of a square array"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "346bcf67-e5be-49d2-8e22-31d87ed416cd",
   "metadata": {},
   "outputs": [
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "Enter size of square array:  2\n",
      "Enter a square array in row-wise manner:  1 2 2 1\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "SUCCESS: Reshape operation completed\n",
      "Given square array is\n",
      "[[1 2]\n",
      " [2 1]]\n",
      "The eigenvalues of the above square array is\n",
      "[ 3. -1.]\n",
      "The eigenvectors of the above square array is\n",
      "[[ 0.70710678 -0.70710678]\n",
      " [ 0.70710678  0.70710678]]\n"
     ]
    }
   ],
   "source": [
    "arr_shape = int(input(\"Enter size of square array: \"))\n",
    "arr = list(map(int,input(\"Enter a square array in row-wise manner: \").split()))\n",
    "\n",
    "if len(arr) == arr_shape**2 :\n",
    "    sq_arr = np.array(arr, dtype=int).reshape(arr_shape, arr_shape)\n",
    "    print(\"\\nSUCCESS: Reshape operation completed\")\n",
    "    print(f\"Given square array is\")\n",
    "    print(sq_arr)\n",
    "    \n",
    "    eig_val, eig_vec = np.linalg.eig(sq_arr)\n",
    "    print(\"The eigenvalues of the above square array is\")\n",
    "    print(eig_val)\n",
    "    print(\"The eigenvectors of the above square array is\")\n",
    "    print(eig_vec)\n",
    "else:\n",
    "    print(f\"ERROR: Cannot reshape array of size {len(arr)} into {(arr_shape, arr_shape)}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "897a5000-e52d-4a07-afc1-2b722ec423e5",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
